﻿//
// This file is part of AVSReflector project
// Copyright (C) 2011 Yuan Pengfei
//

using System;
using System.Collections.Generic;
using System.Text;

namespace AVSReflector.Core
{
    public class CameraParametersExtension : INode
    {
        public uint camera_id;
        public uint height_of_image_device;
        public uint focal_length;
        public uint f_number;
        public uint vertical_angle_of_view;
        public uint camera_position_x_upper;
        public uint camera_position_y_upper;
        public uint camera_position_z_upper;
        public uint camera_position_x_lower;
        public uint camera_position_y_lower;
        public uint camera_position_z_lower;
        public uint camera_direction_x;
        public uint camera_direction_y;
        public uint camera_direction_z;
        public uint image_plane_vertical_x;
        public uint image_plane_vertical_y;
        public uint image_plane_vertical_z;

        public string[] GetInfo()
        {
            List<string> lines = new List<string>();
            lines.Add("camera_id = " + camera_id);
            lines.Add("height_of_image_device = " + height_of_image_device);
            lines.Add("focal_length = " + focal_length);
            lines.Add("f_number = " + f_number);
            lines.Add("vertical_angle_of_view = " + vertical_angle_of_view);
            lines.Add("camera_position_x_upper = " + camera_position_x_upper);
            lines.Add("camera_position_x_lower = " + camera_position_x_lower);
            lines.Add("camera_position_y_upper = " + camera_position_y_upper);
            lines.Add("camera_position_y_lower = " + camera_position_y_lower);
            lines.Add("camera_position_z_upper = " + camera_position_z_upper);
            lines.Add("camera_position_z_lower = " + camera_position_z_lower);
            lines.Add("camera_direction_x = " + camera_direction_x);
            lines.Add("camera_direction_y = " + camera_direction_y);
            lines.Add("camera_direction_z = " + camera_direction_z);
            lines.Add("image_plane_vertical_x = " + image_plane_vertical_x);
            lines.Add("image_plane_vertical_y = " + image_plane_vertical_y);
            lines.Add("image_plane_vertical_z = " + image_plane_vertical_z);
            return lines.ToArray();
        }

        public static CameraParametersExtension Parse(BitStream s)
        {
            CameraParametersExtension ret = new CameraParametersExtension();
            s.Read(1);
            ret.camera_id = s.Read(7);
            s.Read(1);
            ret.height_of_image_device = s.Read(22);
            s.Read(1);
            ret.focal_length = s.Read(22);
            s.Read(1);
            ret.f_number = s.Read(22);
            s.Read(1);
            ret.vertical_angle_of_view = s.Read(22);
            s.Read(1);
            ret.camera_position_x_upper = s.Read(16);
            s.Read(1);
            ret.camera_position_x_lower = s.Read(16);
            s.Read(1);
            ret.camera_position_y_upper = s.Read(16);
            s.Read(1);
            ret.camera_position_y_lower = s.Read(16);
            s.Read(1);
            ret.camera_position_z_upper = s.Read(16);
            s.Read(1);
            ret.camera_position_z_lower = s.Read(16);
            s.Read(1);
            ret.camera_direction_x = s.Read(22);
            s.Read(1);
            ret.camera_direction_y = s.Read(22);
            s.Read(1);
            ret.camera_direction_z = s.Read(22);
            s.Read(1);
            ret.image_plane_vertical_x = s.Read(22);
            s.Read(1);
            ret.image_plane_vertical_y = s.Read(22);
            s.Read(1);
            ret.image_plane_vertical_z = s.Read(22);
            s.Read(1);
            s.Read(32);
            s.SkipToCode(0x1, 24);
            return ret;
        }
    }
}
